home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
programming
/
other
/
jikes
/
src
/
control.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
46KB
|
1,197 lines
// $Id: control.cpp,v 1.4 1999/03/10 19:59:21 shields Exp $
//
// This software is subject to the terms of the IBM Jikes Compiler
// License Agreement available at the following URL:
// http://www.ibm.com/research/jikes.
// Copyright (C) 1996, 1998, International Business Machines Corporation
// and others. All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
#include "config.h"
#include <sys/stat.h>
#include "control.h"
#include "scanner.h"
#include "parser.h"
#include "semantic.h"
#include "unicode.h"
#include "error.h"
#include "bytecode.h"
Control::Control(ArgumentExpander &arguments, Option &option_) : return_code(0),
option(option_),
dot_classpath_index(0),
system_semantic(NULL),
semantic(1024),
needs_body_work(1024),
type_trash_bin(1024),
input_java_file_set(1021),
input_class_file_set(1021),
expired_file_set(),
recompilation_file_set(1021),
Object_type(NULL),
Cloneable_type(NULL),
Serializable_type(NULL),
String_type(NULL),
Void_type(NULL),
Boolean_type(NULL),
Byte_type(NULL),
Short_type(NULL),
Character_type(NULL),
Integer_type(NULL),
Long_type(NULL),
Float_type(NULL),
Double_type(NULL),
Class_type(NULL),
StringBuffer_type(NULL),
Throwable_type(NULL),
RuntimeException_type(NULL),
Error_type(NULL),
int_pool(&bad_value),
long_pool(&bad_value),
float_pool(&bad_value),
double_pool(&bad_value),
Utf8_pool(&bad_value)
#ifdef TEST
, line_count(0),
class_files_read(0),
class_files_written(0),
class_file_id(0),
input_files_processed(0)
#endif
{
ProcessGlobalNameSymbols();
ProcessUnnamedPackage();
ProcessPath();
ProcessSystemInformation();
//
// Instantiate a scanner and a parser and initialize the static members for the semantic processors.
//
scanner = new Scanner(*this);
parser = new Parser();
SemanticError::StaticInitializer();
//
// Process all file names specified in command line
//
ProcessNewInputFiles(input_java_file_set, arguments, option.first_file_index);
//
// For each input file, copy it into the input_files array and process its package declaration.
//
StoragePool *ast_pool = new StoragePool(64); // how much space do we need? estimate 64 tokens.
FileSymbol **input_files = new FileSymbol*[input_java_file_set.Size() + 1];
int num_files = 0;
for (FileSymbol *file_symbol = (FileSymbol *) input_java_file_set.FirstElement();
file_symbol;
file_symbol = (FileSymbol *) input_java_file_set.NextElement())
{
input_files[num_files++] = file_symbol;
scanner -> Scan(file_symbol);
if (file_symbol -> lex_stream) // did we have a successful scan!
{
AstPackageDeclaration *package_declaration = parser -> PackageHeaderParse(file_symbol -> lex_stream, ast_pool);
ProcessPackageDeclaration(file_symbol, package_declaration);
ast_pool -> Reset();
}
}
//
//
//
FileSymbol *main_file_clone;
if (num_files > 0)
main_file_clone = input_files[0] -> Clone();
else
{
//
// Some name, any name !!! We use dot_name_symbol as a bad file name because
// no file can be named ".".
//
FileSymbol *file_symbol = classpath[dot_classpath_index] -> RootDirectory() -> InsertFileSymbol(dot_name_symbol);
file_symbol -> directory_symbol = classpath[dot_classpath_index] -> RootDirectory();
file_symbol -> SetJava();
main_file_clone = file_symbol -> Clone();
}
main_file_clone -> semantic = new Semantic(*this, main_file_clone);
system_semantic = main_file_clone -> semantic;
scanner -> SetUp(main_file_clone);
#ifdef WIN32_FILE_SYSTEM
//
//
//
if (option.BadMainDisk())
{
system_semantic -> ReportSemError(SemanticError::NO_CURRENT_DIRECTORY,
0,
0);
}
#endif
//
//
//
for (int o = 0; o < option.bad_options.Length(); o++)
{
system_semantic -> ReportSemError((SemanticError::SemanticErrorKind) option.bad_options[o] -> kind,
0,
0,
option.bad_options[o] -> name);
}
//
//
//
for (int l = 0; l < bad_zip_filenames.Length(); l++)
{
system_semantic -> ReportSemError(SemanticError::CANNOT_OPEN_ZIP_FILE,
0,
0,
bad_zip_filenames[l]);
}
//
//
//
if (system_package -> directory.Length() == 0)
{
system_semantic -> ReportSemError(SemanticError::PACKAGE_NOT_FOUND,
0,
0,
StringConstant::US_java_SL_lang);
}
//
// When the -d option is specified, create the relevant
// directories if they don't already exist.
//
if (option.directory)
{
if (! ::SystemIsDirectory(option.directory))
{
for (char *ptr = option.directory; *ptr; ptr++)
{
char delimiter = *ptr;
if (delimiter == U_SLASH)
{
*ptr = U_NULL;
if (! ::SystemIsDirectory(option.directory))
::SystemMkdir(option.directory);
*ptr = delimiter;
}
}
::SystemMkdir(option.directory);
if (! ::SystemIsDirectory(option.directory))
{